package com.onesports.intelligent.k12.polarlight.service.student.manage;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.onesports.intelligent.k12.polarlight.domain.dto.sys.WxQueryDTO;
import com.onesports.intelligent.k12.polarlight.domain.entity.student.Student;
import com.onesports.intelligent.k12.polarlight.domain.vo.student.StudentDetailVO;
import com.onesports.intelligent.k12.polarlight.domain.vo.sys.WxQueryVO;
import com.onesports.intelligent.k12.polarlight.mapper.sys.WxUserMapper;
import com.onesports.intelligent.k12.polarlight.service.course.CourseService;
import com.onesports.intelligent.k12.polarlight.service.order.OrderService;
import com.onesports.intelligent.k12.polarlight.service.student.StudentAttendanceService;
import com.onesports.intelligent.k12.polarlight.service.student.StudentService;
import com.onesports.intelligent.k12.polarlight.service.student.WxUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

/**
 * @author FPH
 * @since 2022年7月20日09:55:46
 */
@Service
@RequiredArgsConstructor
public class PlatformMembershipService {
    private final WxUserService wxUserService;
    private final CourseService courseService;

    private final StudentService studentService;

    private final StudentAttendanceService studentAttendanceService;

    private final WxUserMapper wxUserMapper;

    private final OrderService orderService;
    /**
     * 查看详情
     * @param id
     * @return
     */
    public StudentDetailVO detailVO(String id, List<String> campusIds,Boolean flag){
        StudentDetailVO resultVO = new StudentDetailVO();
        Student entity = Optional.ofNullable(studentService.getById(id)).orElse(new Student());
        BeanUtils.copyProperties(entity,resultVO);


        //课程列表
        resultVO.setCourseList(courseService.courseList(id, campusIds));
        resultVO.setClassRecords(studentAttendanceService.classRecordList(id,campusIds));
        if(flag){
            //flag为true为运营端
            resultVO.setPaymentRecords(orderService.getStudentOrder1(id));
        }else{
            resultVO.setPaymentRecords(orderService.getStudentOrder(id));
        }
        return resultVO;
    }

    /**
     * 平台会员列表查询
     * @param wxQueryDTO
     * @return
     */
    public IPage<WxQueryVO> queryPage(WxQueryDTO wxQueryDTO){
        return wxUserMapper.queryPage(new Page<WxQueryVO>(wxQueryDTO.getPage(),wxQueryDTO.getRow()), wxQueryDTO);
    }
}
